@extends('layouts.mobile')

@section('title', '订单详情')

@section('content')
    <div class="order-detail">
        <div class="order-header">
            @if ($order['trade_status'] == 1)
                <div class="order-status">
                    <strong>等待买家付款</strong>
                </div>
                <img src="{{asset('images/trade/waitPay.png')}}" class="status-icon">
            @endif
                @if ($order['trade_status'] == 2)
                    <div class="order-status">
                        <strong>等待卖家发货</strong>
                    </div>
                    <img src="{{asset('images/trade/waitSend.png')}}" class="status-icon">
                @endif
                @if ($order['trade_status'] == 3)
                    <div class="order-status">
                        <strong>卖家已发货</strong>
                    </div>
                    <img src="{{asset('images/trade/send.png')}}" class="status-icon">
                @endif
                @if ($order['trade_status'] == 4)
                    <div class="order-status">
                        <strong>交易成功</strong>
                    </div>
                    <img src="{{asset('images/trade/received.png')}}" class="status-icon">
                @endif
        </div>
        <div class="address">
            <div class="iconfont icon-location"></div>
            <div class="info">
                <p style="display: flex;">
                    <span style="flex: 1;">收货人:{{$shipping['consignee']}}</span>
                    <span>联系电话:{{$shipping['phone']}}</span>
                </p>
                <p>收货地址:{{$shipping['province']}} {{$shipping['city']}} {{$shipping['district']}} {{$shipping['street']}}</p>
            </div>
        </div>

        <div class="order-info">
            <div class="shop-name">
                <span class="iconfont icon-shop"></span>
                <span>{{$order['shop_name']}}</span>
            </div>
            <div class="items">
                @foreach ($items as $item)
                    <div class="item">
                        <div class="image bg-cover" style="background-image: url({{image_url($item['thumb'])}})"></div>
                        <div class="name">
                            <h3>{{$item['title']}}</h3>
                        </div>
                        <div class="attrs">
                            <p>￥{{$item['price']}}</p>
                            <p>x{{$item['quantity']}}</p>
                        </div>
                    </div>
                @endforeach
            </div>
            <div class="groups">
                <div class="group">
                    <div class="label-name">商品总价</div>
                    <div class="label-text">￥{{$order['total_fee']}}</div>
                </div>
                <div class="group">
                    <div class="label-name">运费</div>
                    <div class="label-text">￥{{$order['shipping_fee']}}</div>
                </div>
                <div class="group">
                    <div class="label-name">实付款</div>
                    <div class="label-text" style="color: #f00; font-size: 16px;">
                        ￥{{formatAmount($order['shipping_fee']+$order['order_fee'])}}
                    </div>
                </div>
            </div>
        </div>

        <ul class="trade-info">
            <li>订单号: {{$order['order_no']}}</li>
            <li>交易流水: {{$order['trade_no']}}</li>
            <li>创建时间: {{@date('Y-m-d H:i:s', $order['created_at'])}}</li>
        </ul>
        @if ($order['trade_status'] == 1)
            <div class="pay" id="pay">
                <div class="button" id="callPay">立即支付</div>
            </div>
        @endif
    </div>
    <script type="text/javascript">
        $("#callPay").on('tap', function () {
            $.ajax({
                url:'/mobile/pay/getsign',
                data:{order_id:'{{$order_id}}'},
                success:function (response) {
                    //alert(JSON.stringify(response));
                    callPay({
                        params:response,
                        success:function (res) {
                            $("#pay").hide();
                            window.location.href = '/mobile/pay/success?order_id={{$order_id}}';
                        },
                        fail:function (res) {
                            //alert(res.err_msg);
                        }
                    })
                },
            });
        });
    </script>
@stop
